﻿window.addEventListener('load', function () {
    var sum1 = document.querySelector('.tubiao-sum1 img');
    var sum2 = document.querySelector('.tubiao-sum2 img');
    var bs_ss = document.querySelector('.bs_ss');
    var bs_ssWidth = bs_ss.offsetWidth;
    var ul = bs_ss.querySelector('ul');

    //克隆第一章图片
    var first = ul.children[0].cloneNode(true);
    ul.appendChild(first);
    //点击右边按钮，实现滚动效果
    var num = 0;
    var flag = true;
    sum1.addEventListener('click', function () {
        if (flag) {
            flag = false;
            if (num == ul.children.length - 1)
            {
                ul.style.left = 0;
                num = 0;
            }
            num++;
            animate(ul, -num * bs_ssWidth, function () {
                flag = true;
            });
        }
    })
    //点击右边按钮，实现滚动
    sum2.addEventListener('click', function () {
        if (flag) {
            flag = false;
            if (num == 0)
            {
                num = ul.children.length - 1;
                ul.style.left = -num * bs_ssWidth + 'px';
            }
            num--;
            animate(ul, -num * bs_ssWidth, function () {
                flag = true;
            });
        }
    });
})